package cn.ld.module.system.dal.mapper.sms;

import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.module.system.controller.admin.sms.vo.template.SmsTemplatePageInVO;
import cn.ld.module.system.dal.entity.sms.SmsTemplateEntity;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface SmsTemplateMapper extends BaseMapperX<SmsTemplateEntity> {

    default SmsTemplateEntity selectByCode(String code) {
        return selectOne(SmsTemplateEntity::getCode, code);
    }

    default PageResult<SmsTemplateEntity> selectPage(SmsTemplatePageInVO inVO) {
        return selectPage(inVO, new LambdaQueryWrapperX<SmsTemplateEntity>()
                .eqIfPresent(SmsTemplateEntity::getType, inVO.getType())
                .eqIfPresent(SmsTemplateEntity::getStatus, inVO.getStatus())
                .likeIfPresent(SmsTemplateEntity::getCode, inVO.getCode())
                .likeIfPresent(SmsTemplateEntity::getContent, inVO.getContent())
                .likeIfPresent(SmsTemplateEntity::getApiTemplateId, inVO.getApiTemplateId())
                .eqIfPresent(SmsTemplateEntity::getChannelId, inVO.getChannelId())
                .betweenIfPresent(SmsTemplateEntity::getCreateTime, inVO.getCreateTime())
                .orderByDesc(SmsTemplateEntity::getId));
    }

    default Long selectCountByChannelId(Long channelId) {
        return selectCount(SmsTemplateEntity::getChannelId, channelId);
    }

}
